<?php
namespace app\admin\model;

use think\facade\Db;
use think\Model;
use think\model\concern\SoftDelete;

class GoodsProp extends Model
{
    use SoftDelete;
    protected $pk = 'pid';
    protected $deleteTime = 'delete_time';
    public static function getGoodsProp($where,$whereOr,$data)
    {
        $list = GoodsProp::field(true)
            ->where($where)
            ->where(function ($query) use ($whereOr){
                $query->whereOr($whereOr);
            })
            ->paginate([
                'list_rows'=>5,
                'query'=>$data
            ]);
        return $list;
    }
    public static function getPvalues()
    {
        $list = GoodsProp::suffix('_value')
            ->field(true)
            ->select()->toArray();
        return $list;
    }

    //属性列表判断显示
    public static function getIfShowNextAttr($v,$data)
    {
        if ($data['if_show']==1){
            return "<font style='color: red'>显示</font>";
        }else{
            return "<font style='color: green'>不显示</font>";
        }
    }
    //属性添加
    public static function addPropAttr($add,$adds)
    {
        try{
            foreach ($adds as $v){
                $add_value = GoodsProp::suffix('_value')->insertGetId($v);
                $add['pvalues'][] = $add_value;
            }
            $add['pvalues'] = implode(',',$add['pvalues']);
            $res = GoodsProp::strict(true)->save($add);
            $msg = '添加成功';
        }catch (\Exception $e){
            $res = false;
            $msg = $e->getMessage();
        }
        return [$res,$msg];
    }
    //属性添加
    public static function editPropAttr($edit,$adds)
    {
        try{
            foreach ($adds as $v){
                $add_value = GoodsProp::suffix('_value')->insertGetId($v);
                $edit['pvalues'][] = $add_value;
            }
            $edit['pvalues'] = implode(',',$edit['pvalues']);
            $res = GoodsProp::update($edit);
            $msg = '修改成功';
        }catch (\Exception $e){
            $res = false;
            $msg = $e->getMessage();
        }
        return [$res,$msg];
    }
    //属性修改
    public static function goodPropEdit()
    {

    }
    //属性单个软删除
    public static function delProp($get)
    {
        $res = GoodsProp::destroy($get['id']);
        return $res;
    }
    //属性单个软删除
    public static function delsProp($get)
    {
        $id = explode(',',$get['id']);
        $res = GoodsProp::destroy($id);
        return $res;
    }



}